package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.Area;
import com.ruoyi.system.mapper.AreaMapper;
import com.ruoyi.system.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @packageName: com.ruoyi.system.service.impl
 * @user: andyliu
 * @date: 2023/2/18 14:37
 * @email 115176513@qq.com
 * @description: TODO
 */
@Service
public class AreaServiceImpl implements AreaService {
    @Autowired
    private AreaMapper mapper;

    @Override
    public boolean saveOrUpdate(Area area) {
        if(area.getId()==null){
            return mapper.insertArea(area)==1?true:false;
        }
        return mapper.updateArea(area)==1?true:false;
    }

    @Override
    public boolean removeById(Integer id) {
        return mapper.deleteById(id)==1;
    }

    @Override
    public boolean removeByIds(Integer[] ids) {
        int flag =0;
        for(int i=0;i<ids.length;i++){
            flag+=mapper.deleteById(ids[i]);
        }
        return flag==ids.length;
    }

    @Override
    public Area queryById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public List<Area> queryAreas(Area area) {
        return mapper.select(area);
    }
}
